package com.demo.jwt.exception;

import java.io.Serializable;

public class ResponseVo<T> implements Serializable {

    private Boolean status;

    private Integer code;

    private String message;

    private T data;

    private Long timestamp = System.currentTimeMillis();

    public ResponseVo(){

    }

    public ResponseVo(Boolean status, Integer code, String message, T data){
        this.status = status;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseVo<T> simpleBuild(Boolean status, RespStatus respStatus, T data){
        return new ResponseVo<T>(status, respStatus.OK.getCode(), respStatus.OK.getMessge(), data);
    }

    public static <T> ResponseVo<T> ok(T data){
        return simpleBuild(true,RespStatus.OK,data);
    }

    public static ResponseVo error(String message){
        return simpleBuild(false, RespStatus.FAIL, null);
    }

    public static <T> ResponseVo<T> build(RespStatus respStatus, T data){
        return simpleBuild(true, respStatus, data);
    }

    public static <T> ResponseVo<T> buildException(MyException e){
        return new ResponseVo<T>(false,e.getCode(),e.getMessage(),null);
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }
}
